package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuHeGeZhengSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuHeGeZhengSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuHeGeZhengVO;
import com.ct.application.shipping.service.ChuanYuanKuHeGeZhengService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 船员证书-合格证配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员证书-合格证",path="/api/v1/chuanyuankuhegezheng",code = "O1000",sorted = 14)
public class ChuanYuanKuHeGeZhengController extends BaseController {

    @Resource
    private ChuanYuanKuHeGeZhengService chuanYuanKuHeGeZhengService;

    /**
     * 查询船员证书-合格证列表
     * @param chuanYuanKuHeGeZhengSearchPO
     * @return
     */
    @PostMapping("/chuanyuankuhegezheng/list")
    @PermissionApi(title = "查询船员证书-合格证列表",path="/api/v1/chuanyuankuhegezheng/list",code = "O1001",sorted = 1)
    public Page<ChuanYuanKuHeGeZhengVO> findChuanYuanKuHeGeZhengs(@Validated @RequestBody ChuanYuanKuHeGeZhengSearchPO chuanYuanKuHeGeZhengSearchPO) {
        return chuanYuanKuHeGeZhengService.findChuanYuanKuHeGeZheng(chuanYuanKuHeGeZhengSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuankuhegezheng/saveupdate")
    @ApiLog("船员证书-合格证保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-合格证保存和更新",path="/api/v1/chuanyuankuhegezheng/saveupdate",code = "O1003",sorted = 3)
    public ChuanYuanKuHeGeZhengVO saveUpdateChuanYuanKuHeGeZheng(@Validated @RequestBody ChuanYuanKuHeGeZhengSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuHeGeZhengService.updateChuanYuanKuHeGeZheng(savePO);
        }else {
            return chuanYuanKuHeGeZhengService.saveChuanYuanKuHeGeZheng(savePO);
        }
    }

    /**
     * 根据id查询船员证书-合格证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankuhegezheng/get/{id}")
    @PermissionApi(title = "根据id查询船员证书-合格证",path="/api/v1/chuanyuankuhegezheng/get/{id}",code = "O1004",sorted = 4)
    public ChuanYuanKuHeGeZhengVO getChuanYuanKuHeGeZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuHeGeZhengService.getChuanYuanKuHeGeZheng(id);
    }


    /**
     * 根据id删除船员证书-合格证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankuhegezheng/del/{id}")
    @ApiLog("根据id删除船员证书-合格证")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员证书-合格证",path="/api/v1/chuanyuankuhegezheng/del/{id}",code = "O1005",sorted = 5)
    public Boolean delChuanYuanKuHeGeZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuHeGeZhengService.delChuanYuanKuHeGeZheng(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuankuhegezheng/update/status")
    @ApiLog("船员证书-合格证修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-合格证修改状态",path="/api/v1/chuanyuankuhegezheng/update/status",code = "O1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanKuHeGeZhengService.updateStatus(statusRequest);
    }
}
